package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.ChatgroupApply;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IChatgroupApplyService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-31 11:25:21
 */
@Controller
@RequestMapping("/chatgroupApply")
public class ChatgroupApplyController extends BaseController {

    private String PREFIX = "/user/chatgroupApply/";

    @Autowired
    private IChatgroupApplyService chatgroupApplyService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "chatgroupApply.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/chatgroupApply_add")
    public String chatgroupApplyAdd() {
        return PREFIX + "chatgroupApply_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/chatgroupApply_update/{chatgroupApplyId}")
    public String chatgroupApplyUpdate(@PathVariable Long chatgroupApplyId, Model model) {
        ChatgroupApply chatgroupApply = chatgroupApplyService.selectById(chatgroupApplyId);
        model.addAttribute("item",chatgroupApply);
        LogObjectHolder.me().set(chatgroupApply);
        return PREFIX + "chatgroupApply_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return chatgroupApplyService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ChatgroupApply chatgroupApply) {
        chatgroupApplyService.insert(chatgroupApply);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long chatgroupApplyId) {
        chatgroupApplyService.deleteById(chatgroupApplyId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ChatgroupApply chatgroupApply) {
        chatgroupApplyService.updateById(chatgroupApply);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{chatgroupApplyId}")
    @ResponseBody
    public Object detail(@PathVariable("chatgroupApplyId") Long chatgroupApplyId) {
        return chatgroupApplyService.selectById(chatgroupApplyId);
    }
}
